//
//  vdShapeContainer.h
//  Void Dead
//
//  Created by Sidney Just on 19.12.09.
//
//  Copyright © 2009 by Sidney Just
//  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
//  documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
//  and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
//  PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
//  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#import <Foundation/Foundation.h>

#import "vdNode.h"
#import "vdTexNode.h"

#import "vdHeader.h"

/**
 * This struct represents one shape for an shape or atlas shape container.
 **/
typedef struct {
	/**
	 * The x position of the shape
	 **/
	float pos_x;
	
	/**
	 * The y position of the shape
	 **/
	float pos_y;
	
	/**
	 * The size on the x axis of the shape. This will be the same as the textur width or (if you use a atlas shape container) the size of the tile
	 **/
	float size_x;
	
	/**
	 * The size on the x axis of the shape. This will be the same as the textur height or (if you use a atlas shape container) the size of the tile
	 **/
	float size_y;
	
	/**
	 * The scale on the x axis of the shape
	 **/
	float scale_x;
	
	/**
	 * The scale on the y axis of the shape
	 **/
	float scale_y;
	
	/**
	 * The rotation of the shape in degrees!
	 **/
	float rotation;
	
	/**
	 * The beginning of the x axis atlas texture in pixels. This value wont be updated if you set it by hand! (The value is only needed if you use a atlas shape container)
	 **/
	float atlas_x;
	/**
	 * The beginning of the y axis atlas texture in pixels. This value wont be updated if you set it by hand! (The value is only needed if you use a atlas shape container)
	 **/
	float atlas_y;
	
	/**
	 * The key of the shape.
	 **/
	int key;
} vdInlineShape;



/**
 * A shape container is a class, that can hold many shapes with the same texture, without using vdShape classes that holds the drawing code an variables.
 * <br>As visiting a class is really slow in Obj-C, shape container can render many shapes much faster than many vdShape instances!
 **/
@interface vdShapeContainer : vdNode {
	//\cond
	/**
	 * All shapes handled by the container
	 **/
	vdInlineShape **shape;
	
	/**
	 * The number of shapes inside the container
	 **/
	int shapeCount;
	
	/**
	 * Vertices of all shapes (every shape uses 12 vertices!)
	 **/
	GLfloat *vertices;
	
	/**
	 * Texture coordinates of all shapes (every shape uses 12 tex coords!)
	 **/
	GLfloat *texCoords;
	
	int appendSize;
	unsigned int vertexPos;
	
	BOOL changed;
	// \endcond
}

/**
 * The number of shapes in this container.
 **/
@property (readonly) int shapeCount;

/**
 * Sets the texture of the container
 @param tex The new texture of the container or NULL
 @remark The texture will be used for all shapes!
 **/
- (void)setTexture:(vdTexNode *)tex;

/**
 * Adds a new shape to the container. This will automatically be over all older shapes!!!
 @param point The position of the shape, relative to the container position
 @return Pointer to the new shape
 **/
- (vdInlineShape *)addShape:(CGPoint)point;

/**
 * Adds a new shape to the container. This will automatically be over all older shapes!!!
 @param point The position of the shape, relative to the container position
 @param key The shape will get the given key which can be used to get the pointer to this shape
 @return Pointer to the new shape
 **/
- (vdInlineShape *)addShape:(CGPoint)point withKey:(int)key;

/**
 * Deletes a shape from the container.
 @param aShape The shape that you want to remove
 **/
- (void)removeShape:(vdInlineShape *)aShape;

/**
 * Returns the next shape after the given shape. This can be used to loop through all shapes in the container.
 @param _shp The shape from what you want to have the next shape or NULL if you want the first shape in this container.
 @return The next shape in the container or NULL if the given shape is the last shape.
 @remark The given shape must be in the container, otherwise the function returns NULL!
 **/
- (vdInlineShape *)nextShape:(vdInlineShape *)_shp;

/**
 * Returns the first shape in the array with the given key or NULL
 @param key The key of the shape
 @return Pointer to the first shape with the key or NULL if no shape with the key exist
 **/
- (vdInlineShape *)getShapeByKey:(int)key;

/**
 * Sets the ne AppendSize.
 @param _size The new size. Must be larger than 0
 **/
- (void)setAppendSize:(int)_size;


/**
 * Sets the texture for this container
 **/
- (void)setTexture:(vdTexNode *)tex;

@end

